﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_Flow_BackManage_Flow_NewFlowList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 53)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
             e.Item.ItemType == ListItemType.AlternatingItem)
        {
            GridView g = (GridView)e.Item.FindControl("GridView1");
            HiddenField hf = (HiddenField)e.Item.FindControl("HiddenField1");
            g.DataSource = Flow_NewFlow_Service.FindFlowsByType(Convert.ToInt32(hf.Value));
            g.DataBind();
        }  
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName=="updateFlow")
        {
            Response.Redirect("UpdateNewFlow.aspx?id="+e.CommandArgument.ToString());
        }
        else if (e.CommandName=="updateFlowManager")
        {
            Response.Redirect("UpdateFlowManager.aspx?id=" + e.CommandArgument.ToString());
        }
        else if (e.CommandName=="delFlow")
        {
            if (Flow_NewFlow_Service.DelNewFlow(Convert.ToInt32(e.CommandArgument)))
            {
                foreach (DataListItem var in this.DataList1.Items)
                {
                    GridView g = (GridView)var.FindControl("GridView1");
                    HiddenField hf = (HiddenField)var.FindControl("HiddenField1");
                    g.DataSource = Flow_NewFlow_Service.FindFlowsByType(Convert.ToInt32(hf.Value));
                    g.DataBind();
                }
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功！')", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(),"","alert('删除失败！请重试！')",true);
            }
        }
        else if (e.CommandName=="showFlowStep")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "window.showModalDialog ('FlowStepList.aspx?id=" + e.CommandArgument.ToString() + "', '','status:no;center:yes;scroll:yes;resizable:no;help:no;dialogWidth:550px;dialogHeight:400px');", true);
        }
        else if (e.CommandName=="copyFlow")
        {
            Response.Redirect("CopyNewFlow.aspx?id="+e.CommandArgument.ToString());
        }
        else if (e.CommandName=="clearFlowWorks")
        {
            if (Flow_NewWork_Service.DelAllWorksByFlowId(Convert.ToInt32(e.CommandArgument)))
            {
                ClientScript.RegisterStartupScript(this.GetType(),"","alert('操作成功！')",true);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('操作失败！请重试！')", true);

            }
        }
        else if(e.CommandName=="showForm")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "window.open('../../page/Flow_ShowForm.aspx?id="+e.CommandArgument.ToString()+"')", true);
        }
    }
}
